<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <base href="<%=basePath%>">
    <title>超市后台</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/main.css">
    <script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
	<script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
	<script src="${pageContext.request.contextPath}/js/main.js"></script>
	<script src="http://cdn.bootcss.com/angular.js/1.4.5/angular.min.js"></script>
    <script type="text/javascript">
var image = '';
    function selectImage(file){
        if(!file.files || !file.files[0]){
            return;
        }
        var reader = new FileReader();
        reader.onload = function(evt){
            document.getElementById('image').src = evt.target.result;
            image = evt.target.result;
        };
        reader.readAsDataURL(file.files[0]);
    }
  
    function sureCard(){
       var card=/^\d{1,20}$/;
     var productCard=$("#productCard").val();
     if(!card.test(productCard)){
        $("#sureCard").text("请输入1到20位数字").css("color","red")
        $("#productCard").val("")
     }else{
          $("#sureCard").text("") 
     }
    }
    function surePrice1(){
    var  price=/^(0|[1-9][0-9]{0,5})(\.[0-9]{1,2})?$/;
    var productPrice=$("#productPrice").val();
    if(!price.test(productPrice)){
     $("#surePrice").text("请输入正确的价格，小数点以后不能超过两位").css("color","red");
     $("#productPrice").val("")
    }else{
          $("#surePrice").text("") 
     }
    }

  function submitProduct(){
      if($("#productCard").val()){
           if($("#productPrice").val()){
               if($("#productName").val()){
                  if($("#productFile").val()){
                    if($("#selectType2").find("option").val()){
                          $("#productForm").submit()
                    }else{
                      alert("请输入商品类型")
                    }                
                  }else{
                     alert("请添加略缩图")
                  }
               }else{
                  alert("请输入商品名称")
               }  
           }else{
               alert("请输入商品价格")
           }                
      }else{
        alert("请输入商品条形码")
      }
  }
</script>

<style>
    .main_div{height: 560px;min-width: 1000px}
     form span {
            float: left;
            width: 90px;
            height: 52px;
            line-height: 52px;
            padding-left: 20px;
            background-color: white;
        }
</style>
</head>
<body>
<%@ include file="header.jsp" %>
<%@ include file="left.jsp" %>
<div id="index" style="position: absolute;left: 180px;top: 80px;bottom: 0;right: 0;">

<section id="main">

    <div class="scrollbar1-1" id="style1-1">
        <div class="main_div">
            <div class="main_title">
                <span>录入商品</span>
            </div>
            <form class="form-horizontal" id="productForm" action="productaAction/inputProductFileUpload" style="margin-top: 30px" enctype="multipart/form-data" method="post">
                <div class="form-group">
                    <label for="inputEmail1" class="col-xs-1 control-label">商品分类</label>
                    <div class="col-xs-2">
                        <select id="selectType1" class="col-xs-12"  onclick="change1(this.value,'#selectType2');">
                              
                        </select>
                    </div>
                   <div class="col-xs-2">
                        <select id="selectType2" class="col-xs-12"  name="goodsType">
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-1 control-label">商品名称</label>
                    <div class="col-xs-3">
                    <input type="text" style="display: none;"  >
                        <input type="text"  name="productName" class="form-control" id="productName"  placeholder="商品名称">
                    </div>
                     <label  maxlength="50" class="col-xs-2 control-label" style="text-align:left;color:#ccc;">请输入正确的商品名称</label>
                </div>
                <div class="form-group">
                    <label  class="col-xs-1 control-label">商品条码</label>
                    <div class="col-xs-3">
                        <input type="text"  onblur="sureCard();" name="barCode" class="form-control" id="productCard" placeholder="商品条码">
                    </div>
                    <label id="sureCard"  class="col-xs-2 control-label" style="text-align:left;color:#ccc">请输入正确并且唯一的商品条码</label>
                </div>
                <div class="form-group">
                    <label  class="col-xs-1 control-label">商品价格</label>
                    <div class="col-xs-3">
                        <input type="text" name="referenceValue"  onblur="surePrice1();"  class="form-control" id="productPrice" placeholder="商品价格">
                    </div>
                    <label id="surePrice"  class="col-xs-2 control-label" style="text-align:left;color:#ccc">请输入正确的商品价格</label>
                </div>
                <div class="form-group">
                    <label class="col-xs-1 control-label">略缩图上传</label>
                    <div class="col-xs-3">
						<input type="file" id="productFile" name="file" onchange="selectImage(this);"/>
						<img id="image" style="width:300px;height:300px" src=""/>
                    </div>
                    <label class="col-xs-2 control-label" style="text-align: left;color: #ff6c29">*必须上传略缩图</label>
                </div>
                <div class="form-group">
                    <label class="col-xs-1 control-label">商品介绍</label>
                    <div  class="col-xs-4">
                        <textarea class="col-xs-12" rows="5" name="productDetail"></textarea>
                    </div>
                </div>
                <div class="form-group">
                    <div  class="col-xs-4 col-xs-offset-2">
                        <input class="col-xs-4 btn btn-primary" value="提交审核" onclick="submitProduct()"/>
                        <input type="text"  style="display:none" id="isOK" value="${isOK}">
                    </div>
                </div>
      
             </form>

      </div>

    </div>
</section>
</div>
<script>
   $(function(){
      if($("#isOK").val()=="false"){
          alert("提交失败")
      }else if($("#isOK").val()=="falseCode"){
         alert("商品条码已存在")
      }else if($("#isOK").val()==""){
          
      }else{
         alert("提交成功")
      }
   })
</script>
</body>
</html>